package com.abhinav.generics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class GenericTest {

	public static <T> void copy(Collection<T> from, Collection<? super T> to) {
	}

	public static void addElements(Collection list) {
		list.add(3);
		list.add(1.2);
	}

	public static void main(String[] args) {
		Collection<Dog> dogs = new ArrayList<Dog>();
		Dog aDog = new Dog();

		aDog.playWith(dogs);

		ArrayList<Dog> dogList1 = new ArrayList<Dog>();
		ArrayList<Dog> dogList2 = new ArrayList<Dog>();
		ArrayList<Animal> animalList = new ArrayList<Animal>();

		copy(dogList1, animalList);

		Collection<Integer> coll = new ArrayList<Integer>();
		Foo.foo1(coll);

		ArrayList lst = new ArrayList();
		Foo.foo2(lst);

		ArrayList<Integer> lst2 = new ArrayList<Integer>();
		//addElements(lst2);
		//lst2.add(3.2);
		addElements(Collections.checkedList(lst, Integer.class));

		int total = 0;
		for (int val : lst2) {
			total += val;
		}

		System.out.println("Total is : " + total);
		
		Set<? extends Object> set = new HashSet<>();

	}
}

abstract class Animal {
	public void playWith(Collection<? extends Animal> playGroup) {
		for (Animal animal : playGroup)
			System.out.println("Playing with animal: " + animal);
	}

}

class Dog extends Animal {
	public void playWith(Collection<? extends Animal> playGroup) {
		for (Animal animal : playGroup)
			System.out.println("Playing with dog: " + animal);
	}
}

class Foo {
	public static void foo1(Collection c) {
	}

	public static void foo2(Collection<Integer> c) {
	}

}

class MyList<T extends Dog & Comparable> {
	public T ref;
}